/**
 * 下载文件兼容性处理。
 * @param url 下载文件的url
 */
export default function downloadFile(url) {
    if (!url || typeof url !== "string") {
        throw new Error("download url is avalid!");
    }

    const linkEl = document.createElement("a");

    if ("download" in linkEl) {
        const filename = url.substr(url.lastIndexOf("/"));
        linkEl.download = filename;
        linkEl.target = "_blank";
        document.body.appendChild(linkEl);
        linkEl.href = url;
        linkEl.click();
        linkEl.remove();
    } else {
        const win = window.open(url, "_self");
        win.opener = null;
    }
}
